<?php

namespace app\models;
use app\components\BaseActiveRecord;
use Yii;

/**
 * This is the model class for table "{{%post}}".
 *
 * @property int $id
 * @property int $cid 分类
 * @property int $type
 * @property string $title 标题
 * @property string $description
 * @property string $content 内容
 * @property string $tags 标签
 * @property string $slug
 * @property string $thumbnail 缩略图
 * @property string $rate
 * @property int $attachments
 * @property int $views 浏览数
 * @property int $comments 评论数
 * @property int $likes 赞
 * @property int $up_count
 * @property int $down_count
 * @property int $is_top 推荐
 * @property int $is_comment 禁止评论
 * @property int $status 状态
 * @property int $ctime 发布时间
 * @property int $utime 更新时间
 */
class Post extends BaseActiveRecord{

    /**
     * @inheritdoc
     */
    public static function tableName(){
        return '{{%post}}';
    }

    /**
     * @inheritdoc
     */
    public function rules(){
        return [
            [['slug'], 'unique', 'skipOnEmpty' => TRUE],
            [['title', 'cid', 'type'], 'required'],

            [['cid', 'type', 'attachments', 'views', 'comments', 'likes', 'up_count', 'down_count', 'is_top', 'is_comment', 'status', 'ctime', 'utime'], 'integer'],
            [['content'], 'default', 'value' => ''],
            [['content'], 'string'],
            [['rate'], 'number'],
            [['title', 'tags'], 'string', 'max' => 200],
            [['description'], 'string', 'max' => 300],
            [['slug', 'thumbnail'], 'string', 'max' => 120],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels(){
        return [
            'id' => 'ID',
            'cid' => 'Cid',
            'type' => 'Type',
            'title' => 'Title',
            'description' => 'Description',
            'content' => 'Content',
            'tags' => 'Tags',
            'slug' => 'Slug',
            'thumbnail' => 'Thumbnail',
            'rate' => 'Rate',
            'attachments' => 'Attachments',
            'views' => 'Views',
            'comments' => 'Comments',
            'likes' => 'Likes',
            'up_count' => 'Up Count',
            'down_count' => 'Down Count',
            'is_top' => 'Is Top',
            'is_comment' => 'Is Comment',
            'status' => 'Status',
            'ctime' => 'Ctime',
            'utime' => 'Utime',
        ];
    }

    public function getPostMeta(){
        return $this->hasOne(PostMeta::class, ['post_id' => 'id']);
    }
}
